package com.jiukuaidao.zhulin.module.user;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.jiukuaidao.library.base.BaseActivity;
import com.jiukuaidao.library.util.ToastUtil;
import com.jiukuaidao.zhulin.R;
import com.jiukuaidao.zhulin.data.TaskProvider;
import com.jiukuaidao.zhulin.module.CommWatcher;
import com.jiukuaidao.zhulin.module.user.contract.SavePasswordContract;
import com.jiukuaidao.zhulin.module.user.presenter.SavePasswordPresenter;

import butterknife.BindView;

/**
 * Author : PaiTaSuo
 * Date : 2016/5/26
 * Description : 找回密码（保存密码）
 */
public class SavePasswordActivity extends BaseActivity<SavePasswordContract.Presenter> implements View.OnClickListener, SavePasswordContract.View {
    @BindView(R.id.titile_left_imageview)
    ImageView mLeftImg;
    @BindView(R.id.titile_text)
    TextView mTitileText;
    @BindView(R.id.et_passwordd)
    EditText mEtPassword;
    @BindView(R.id.et_psd_againn)
    EditText mEtPwdAgainn;
    @BindView(R.id.bt_save_password)
    Button mBtnSavePwd;
    public String mPhone;
    public String mCode;

    @Override
    protected View getTargetView() {
        return null;
    }


    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_save_psw;
    }

    @Override
    protected void handleBundle(Bundle bundle) {
        mPhone = bundle.getString("phone");
        mCode = bundle.getString("pwd_code");
    }

    @Override
    protected void init() {
        mTitileText.setText(R.string.password_find);
        new SavePasswordPresenter(TaskProvider.provideTasksRepository(this), this);
        setOnClickListener();
        mEtPwdAgainn.addTextChangedListener(new CommWatcher(mBtnSavePwd, CommWatcher.PWDLOGINBTN));
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_save_password:
                mPresenter.start();
                break;
            case R.id.titile_left_imageview:
                finish();
                break;
        }
    }

    public void setOnClickListener() {
        mBtnSavePwd.setOnClickListener(this);
        mLeftImg.setOnClickListener(this);
    }

    @Override
    public String getMobile() {
        return mPhone;
    }

    @Override
    public String getVeriCode() {
        return mCode;
    }

    @Override
    public String getPassword() {
        return mEtPassword.getText().toString();
    }

    @Override
    public String getTrPassword() {
        return mEtPwdAgainn.getText().toString();
    }

    @Override
    public void toast(String msg) {
        ToastUtil.show(msg, Toast.LENGTH_SHORT);
    }

    @Override
    public void setJump() {
        if (FindPasswordActivity.mInstance != null) {
            FindPasswordActivity.mInstance.finish();
        }
        finish();
    }
}
